var listPage = avalon.define({
	$id: "listPage",
	noData:"",
	messages: []
});
mui.ready(function() {
	var uid = $("#uid").val();
	if("" == uid) {
		mui.openWindow({
			url: "dahua://login"
		});
		return false;
	}
	
	var pageNo = 1;
	var mui_message = mui('#message-list');
	mui.init({
		pullRefresh: {
			container: "#message-list",
			down: {
				height: 50,
				auto: true,
				contentdown: $.i18n.prop('contentDown'),
				contentover: $.i18n.prop('contentOver'),
				contentrefresh: $.i18n.prop('contentRefresh'),
				callback: function() {
					listPage.noData="";
					setTimeout(function() {
						pageNo = 1;
						mui.ajax('/message/list.json', {
							data: {
								uid: uid,
								pageNo: pageNo
							},
							dataType: 'json',
							success: function(data) {
								listPage.messages = data;
								mui_message.pullRefresh().endPulldownToRefresh();
								
								if(listPage.messages.length==0){
									listPage.noData="<img src='../../resources/images/noDataImg.png'><p>No data</p>";
								}
							}
						});
					}, window.DAHUA_CONFIG.LOADING_TIME);

				}
			},
			up: {
				height: 50,
				auto: false,
				contentrefresh: $.i18n.prop('contentRefresh'),
				contentnomore: $.i18n.prop('noData'),
				callback: function() {
					listPage.noData="";
					setTimeout(function() {
						pageNo = pageNo + 1;
						mui.ajax('/message/list.json', {
							data: {
								uid: uid,
								pageNo: pageNo
							},
							dataType: 'json',
							success: function(items) {
								var messages = listPage.messages;
								avalon.each(items, function(i, item) {
									messages.push(item);
								});
								listPage.messages = messages;
								mui_message.pullRefresh().endPullupToRefresh(false);
								if(listPage.messages.length==0){
									listPage.noData="<img src='../../resources/images/noDataImg.png'><p>No data</p>";
								}
							}
						});

					}, window.DAHUA_CONFIG.LOADING_TIME);

				}
			}
		}
	});

	mui(".mui-table-view").on('tap', 'li', function() {
		var mid = this.getAttribute('data-id');
		var url = "pdp.html";
		mui.openWindow({
			url: url + "?mid=" + mid
		});
	});
	

});